﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;

namespace ADayRoiAdmin
{
    public partial class frm_login : Form
    {

        private SqlConnection con;
        private AdayroiClass adayroi;
        
        public frm_login()
        {
            InitializeComponent();
        }

        private void frm_login_Load(object sender, EventArgs e)
        {
            //txt_username.Focus();
            //adayroi = new AdayroiClass(null);

            ////Lay cache file neu co cho vao trong txt_username + password
            //DirectoryInfo di = new DirectoryInfo(System.Environment.GetEnvironmentVariable("userprofile"));
            //string temp_folder = di.ToString() + @"\local settings\temp\Cache_HR";
            //string user = "", pass = "";

            
            //if (user == "" && pass == "")
            //{
            //    txt_password.Text = txt_username.Text = "";
            //    chk_remember.Checked = false;
            //}
            //else
            //{
            //    txt_username.Text = user;
            //    txt_password.Text = pass;
            //    chk_remember.Checked = true;
            //}
        }

        private void btn_login_Click(object sender, EventArgs e)
        {
            if (txt_username.Text.Trim() == String.Empty || txt_password.Text.Trim() == String.Empty)
            {
                MessageBox.Show("Please type username and password.");
                return;
            }

            bool remember = false;
            if (chk_remember.Checked == true)
                remember = true;

            con = adayroi.check_login(txt_username.Text.Trim(), txt_password.Text.Trim(), remember);

            if (con != null)
            {
                TenTruyCapClass.truycap = txt_username.Text.Trim();
                this.Close();
            }

        }

        public SqlConnection connection
        {
            get
            {
                return con;
            }
        }

        private void btn_cancel_Click(object sender, EventArgs e)
        {
            con = null;
            this.Close();
        }


    }

    static class TenTruyCapClass
    {
        private static string tentruycap = "";

        public static string truycap
        {
            get { return tentruycap; }
            set { tentruycap = value; }
        }


    }
}
